import java.io.*;

public class BankAccount {

    private String account; // 账户的名称

    private double balance; // 余额

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    // 转出
    public void out(double money) {
        if (money <= 0) {
            System.out.println("输入的金额必须要大于0");
            return;
        }
        balance = balance - money;// 在原来的余额-转出的余额
    }

    public void in(double money) {
        if (money <= 0) {
            System.out.println("输入的金额要大于0");
            return;
        }
        balance = balance + money; // 在原来的金额上+转入的金额
    }

    @Override
    public String toString() {
        return "BankAccount{" +
                "account='" + account + '\'' +
                ", balance=" + balance +
                '}';
    }

    public static void main(String[] args) {

        // 1.创建一个银行账号
        BankAccount bankAccount = new BankAccount();

        // 2.设置账号的名称
        bankAccount.setAccount("admin");

        // 3.设置账号的余额
        bankAccount.setBalance(200.0);

        // 4.查看账号余额
        System.out.println("余额1:" + bankAccount.getBalance());

        // 5、模拟取50元
        bankAccount.out(50.0);
        bankAccount.out(20.5);
        System.out.println("取2次后的余额:" + bankAccount.getBalance());

        // 6、模拟存钱2次
        bankAccount.in(30.0);
        bankAccount.in(20.0);
        System.out.println("存2次后的余额:" + bankAccount.getBalance());
    }
}
